//
// Created by nilyang on 2021/11/25.
//

#include <cstring>
#include "stl_algorithm.h"

bool Lesser(const std::string &item) {
//    auto cmp = std::bind(std::less<std::string>(),
//            std::string("palcon"), std::placeholders::_1);
    return item < "palcon";
}

bool Greater(int item) {
    return item > 30;
}

void func_stl_find_lt_2017() {
    using namespace std;
    using namespace std::placeholders;
    std::vector<std::string> v{"&v", "foo"};
    std::list<int> lst;
    int num[] = {20, 40, 50};
    for(auto n:num){
        lst.push_back(n);
    }

    vector<string>::iterator p;
    p = find_if(v.begin(), v.end(), Lesser);
    if (p != v.end()) {
        //
    } else {
        // ..
    }

    // 8. 仿函数（函数对象）
    auto grater = std::bind(std::less<int>(), 5, _1);
    grater(12);

    list<int>::iterator q;
    q = std::find_if(lst.begin(), lst.end(), grater);
    // ...
    if (q != lst.end()) {
        //
    } else {
        // ..
    }
}

bool operator<(const std::string &xx, const char *cstr) {
    auto x = std::strcmp(cstr, cstr) < 0;
    return x;
}

void func_stl_find_gt_2017() {
    std::vector<std::string> v = {"hello", "facon", "falcxon"};
    std::list<int> lst{1, 25, 48};
    // since 2021
    auto p = std::find_if(v.begin(),
                          v.end(),
                          [](const std::string &s) { return s < "falcon"; });
    auto q = std::find_if(lst.begin(),
                          lst.end(),
                          [](int x) { return x > 42; });
    if (q != lst.end()) {
        //...
    }


}

#include <iostream>
void func_stl_map_sort() {

}
